package com.run.merchant.controller;

import java.util.List;
import javax.servlet.http.HttpServletResponse;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.run.common.annotation.Log;
import com.run.common.core.controller.BaseController;
import com.run.common.core.domain.AjaxResult;
import com.run.common.enums.BusinessType;
import com.run.merchant.domain.RunNewsInfo;
import com.run.merchant.service.IRunNewsInfoService;
import com.run.common.utils.poi.ExcelUtil;
import com.run.common.core.page.TableDataInfo;

/**
 * 校园资讯信息Controller
 * 
 * @author run
 * @date 2025-05-20
 */
@RestController
@RequestMapping("/merchant/infonews")
public class RunNewsInfoController extends BaseController
{
    @Autowired
    private IRunNewsInfoService runNewsInfoService;

    /**
     * 查询校园资讯信息列表
     */
    @PreAuthorize("@ss.hasPermi('merchant:infonews:list')")
    @GetMapping("/list")
    public TableDataInfo list(RunNewsInfo runNewsInfo)
    {
        startPage();
        List<RunNewsInfo> list = runNewsInfoService.selectRunNewsInfoList(runNewsInfo);
        return getDataTable(list);
    }

    /**
     * 导出校园资讯信息列表
     */
    @PreAuthorize("@ss.hasPermi('merchant:infonews:export')")
    @Log(title = "校园资讯信息", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, RunNewsInfo runNewsInfo)
    {
        List<RunNewsInfo> list = runNewsInfoService.selectRunNewsInfoList(runNewsInfo);
        ExcelUtil<RunNewsInfo> util = new ExcelUtil<RunNewsInfo>(RunNewsInfo.class);
        util.exportExcel(response, list, "校园资讯信息数据");
    }

    /**
     * 获取校园资讯信息详细信息
     */
    @PreAuthorize("@ss.hasPermi('merchant:infonews:query')")
    @GetMapping(value = "/{newsId}")
    public AjaxResult getInfo(@PathVariable("newsId") Long newsId)
    {
        return success(runNewsInfoService.selectRunNewsInfoByNewsId(newsId));
    }

    /**
     * 新增校园资讯信息
     */
    @PreAuthorize("@ss.hasPermi('merchant:infonews:add')")
    @Log(title = "校园资讯信息", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody RunNewsInfo runNewsInfo)
    {
        return toAjax(runNewsInfoService.insertRunNewsInfo(runNewsInfo));
    }

    /**
     * 修改校园资讯信息
     */
    @PreAuthorize("@ss.hasPermi('merchant:infonews:edit')")
    @Log(title = "校园资讯信息", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody RunNewsInfo runNewsInfo)
    {
        return toAjax(runNewsInfoService.updateRunNewsInfo(runNewsInfo));
    }

    /**
     * 删除校园资讯信息
     */
    @PreAuthorize("@ss.hasPermi('merchant:infonews:remove')")
    @Log(title = "校园资讯信息", businessType = BusinessType.DELETE)
	@DeleteMapping("/{newsIds}")
    public AjaxResult remove(@PathVariable Long[] newsIds)
    {
        return toAjax(runNewsInfoService.deleteRunNewsInfoByNewsIds(newsIds));
    }
}
